home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 009a / snpd0493.zip / TRAPDEMO.C < prev    next >
C/C++ Source or Header  |  1993-04-05  |  2KB  |  75 lines

  1. /*
  2. **  Demonstrate TRAPFLAG.ASM
  3. **
  4. **  public domain by Bob Stout
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <dos.h>
  9. #include <int.h>
  10.  
  11. extern void ins09(void);
  12. extern void undo09(void);
  13.  
  14. extern volatile int far ccrcvd;
  15.  
  16. static void biosprt(char *p)
  17. {
  18.       union REGS regs;
  19.  
  20.       while (*p)
  21.       {
  22.             regs.h.ah = 0x0e;             /* Low-level services only!     */
  23.             regs.h.al = *p++;
  24.             regs.x.bx = 0;
  25.             int86(0x10, ®s, ®s);
  26.       }
  27. }
  28.  
  29. static void far my_cc(void)
  30. {
  31.       char *p1 = "Ctrl-";
  32.       char *p2 = "C";
  33.       char *p3 = "Break";
  34.       char *p4 = " received\r\n";
  35.  
  36.       biosprt(p1);
  37.       if (1 == ccrcvd)
  38.             biosprt(p2);
  39.       else  biosprt(p3);
  40.       biosprt(p4);
  41. }
  42.  
  43. main()
  44. {
  45.       unsigned seg, ofs;
  46.       int ch = 0;
  47.  
  48.       setbuf(stdout, NULL);
  49.       my_cc();
  50.       ins09();
  51.       atexit(undo09);
  52.       puts("New Ints 09h & 1Bh installed...");
  53.       puts("Hit Esc to quit...");
  54.       do
  55.       {
  56.             if (kbhit())
  57.             {
  58.                   if (0x1b != (ch = getch()))
  59.                   {
  60.                         if (0x20 > ch)
  61.                         {
  62.                               fputc('^', stdout);
  63.                               ch += '@';
  64.                         }
  65.                         fputc(ch, stdout);
  66.                   }
  67.             }
  68.             if (ccrcvd)
  69.             {
  70.                   my_cc();
  71.                   ccrcvd = 0;
  72.             }
  73.       } while (0x1b != ch);
  74. }
  75.